//
//  CRMBuyerViewController.m
//  XinKaiFa55like
//
//  Created by 55like on 2017/9/25.
//  Copyright © 2017年 55like lj. All rights reserved.
//

#import "CRMBuyerViewController.h"
#import "BuyerNewestTableViewCell.h"
#import "BuyerOwnTableViewCell.h"
#import "BuyerShareTableViewCell.h"
#import "HeaderMenuVIew.h"
#import "YYModel.h"
#import "SelectRightTypeView.h"
#import "EGORefreshTableHeaderView.h"
#import "LoadMoreTableFooterView.h"
#import "BuyerSeacherViewController.h"
#import "BuyerAndSellerDetailViewController.h"


@interface CRMBuyerViewController ()<HeaderMenuVIewDelegate,UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,SelectRightTypeViewDelegate,EGORefreshTableHeaderDelegate,LoadMoreTableFooterDelegate>

@property(nonatomic,strong)UITableView * zhltableView;
@property (nonatomic,assign)NSInteger sharetype;
@property (nonatomic,assign)NSInteger page;
@property (nonatomic,assign)NSInteger pagesize;
@property (nonatomic,strong)NSString * typeid;
@property (nonatomic,strong)UIView * tableviewBackView;
/**最新*/
@property (nonatomic,strong)BuyerNewestModel * newstModel;
/**自有*/
@property (nonatomic,strong)BuyerOwnModel * ownModel;
/**共享*/
@property (nonatomic,strong)BuyerShareModel * shareModel;

@property (nonatomic, strong) EGORefreshTableHeaderView *refreshView;
@property (nonatomic, strong) LoadMoreTableFooterView *loadMoreView;
@property (nonatomic,copy)void (^block)();
@property (nonatomic,strong)HeaderMenuVIew *HeaderView;
//


@end

@implementation CRMBuyerViewController
{
    BOOL refreshing;
    NSMutableArray * arrayTypeRight;
    SelectRightTypeView *selctTypeView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.block = self.userInfo[@"block"];
    //默认最新
    self.sharetype = 0;
    self.page = 1;
    self.pagesize = 10;
    arrayTypeRight = [[NSMutableArray alloc]init];

    [self.view addSubview:self.HeaderView];
    
    [self makeData:0 withMask:SVProgressHUDMaskTypeClear];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(reloadAllData) name: @"CRMList" object:nil];
    
}
-(void)reloadAllData{
    
    
    [self makeData:self.sharetype withMask:SVProgressHUDMaskTypeNil];
    
    
}
//刷新所有数据num为页面type
-(void)makeData:(NSInteger)num withMask:(SVProgressHUDMaskType)make{
    
    
    [self stopLoadmore];
    
    self.page = 1;
    self.pagesize = 10;
    
    self.newstModel = [[BuyerNewestModel alloc] init];
    self.ownModel = [[BuyerOwnModel alloc] init];
    self.shareModel = [[BuyerShareModel alloc] init];
    
    krequestParam
    [dictparam setValue:[NSString stringWithFormat:@"%ld",num] forKey:@"sharetype"];
    [dictparam setValue:[self.userInfo valueForJSONStrKey:@"type"] forKey:@"type"];
    [dictparam setValue:[NSString stringWithFormat:@"%ld",self.page] forKey:@"page"];
    [dictparam setValue:[NSString stringWithFormat:@"%ld",self.pagesize] forKey:@"pagesize"];
    [dictparam setValue:self.typeid forKey:@"typeid"];
    [NetEngine createHttpAction:@"customer" withCache:NO withParams:dictparam withMask:make onCompletion:^(id resData, BOOL isCache) {
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            
            self.tableviewBackView.hidden = YES;
            NSDictionary * dic = resData[@"data"];
            
            switch (num) {
                case 0://最新
                {
                    self.newstModel = [BuyerNewestModel yy_modelWithDictionary:dic];
                    if (self.newstModel.list.count == 0 && self.newstModel.lists.count == 0) {
                        
                        self.tableviewBackView.hidden = NO;

                    }
                    
                    
                    
                }
                    break;
                case 1://自有
                {
                    self.ownModel = [BuyerOwnModel yy_modelWithDictionary:dic];
                    if (self.ownModel.list.count == 0) {
                        
                        self.tableviewBackView.hidden = NO;
                        
                    }
                }
                    break;
                case 2://共享
                {
                    self.shareModel = [BuyerShareModel yy_modelWithDictionary:dic];
                    if (self.shareModel.list.count == 0 && self.shareModel.lists.count == 0) {
                        self.tableviewBackView.hidden = NO;
                        
                    }
                }
                    break;
                default:
                    break;
            }
            
            
            _HeaderView.redArray = @[[dic valueForJSONStrKey:@"isred"]];
            
            
        }else{
            
 
            
        }
        
        [self.zhltableView reloadData];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self stopRefresh];
            
        });
        
    } onError:^(NSError *error) {
        
        
        [self.zhltableView reloadData];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self stopRefresh];
            
        });
        
    }];
    
    
}
//加载数据
-(void)makeMoreData:(NSInteger)num withMask:(SVProgressHUDMaskType)make{
    
    [self stopRefresh];
    
    self.page = self.page + 1;
    
    
    krequestParam
    [dictparam setValue:[NSString stringWithFormat:@"%ld",num] forKey:@"sharetype"];
    [dictparam setValue:[self.userInfo valueForJSONStrKey:@"type"] forKey:@"type"];
    [dictparam setValue:[NSString stringWithFormat:@"%ld",self.page] forKey:@"page"];
    [dictparam setValue:[NSString stringWithFormat:@"%ld",self.pagesize] forKey:@"pagesize"];
    [dictparam setValue:self.typeid forKey:@"typeid"];
    [NetEngine createHttpAction:@"customer" withCache:NO withParams:dictparam withMask:make onCompletion:^(id resData, BOOL isCache) {
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            
            
            NSDictionary * dic = resData[@"data"];
            
            
            
            
            
            switch (num) {
                case 0://最新
                {
                    NSArray * arr = [dic[@"list"] mutableCopy];
                    for (int i = 0; i < [arr count]; i++) {
                        NSDictionary * data = arr[i];
                        
                        [self.newstModel.list addObject: [BuyerNewestListModel yy_modelWithDictionary:data]];
                    
                    }
                    
                }
                    break;
                case 1://自有
                {
                 
                    NSArray * arr = [dic[@"list"] mutableCopy];
                    for (int i = 0; i < [arr count]; i++) {
                        NSDictionary * data = arr[i];
                        
                        [self.ownModel.list addObject: [BuyerOwnListModel yy_modelWithDictionary:data]];
                        
                    }
                }
                    break;
                case 2://共享
                {
                 
                    NSArray * arr = [dic[@"list"] mutableCopy];
                    for (int i = 0; i < [arr count]; i++) {
                        NSDictionary * data = arr[i];
                        [self.shareModel.list addObject: [BuyerShareListModel yy_modelWithDictionary:data]];
                        
                    }
                    
                }
                    break;
                default:
                    break;
            }
            
            
            
        }else{
            
            
            
            
            
            
        }
        
        
        [self.zhltableView reloadData];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self stopLoadmore];
            
        });
        
    } onError:^(NSError *error) {
        
        [self.zhltableView reloadData];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.7 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self stopLoadmore];
            
        });
        
    }];
    
    
}
static NSString * BuyerNewestTableViewCellID  = @"BuyerNewestTableViewCellID";
static NSString * BuyerOwnTableViewCellID  = @"BuyerOwnTableViewCellID";
static NSString * BuyerShareTableViewCellID  = @"BuyerShareTableViewCellID";

-(UITableView *)zhltableView{
    
    if (!_zhltableView) {
        
        UITableView * zhltableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 64 + 45, kScreenWidth, kScreenHeight - 64 - 45) style:UITableViewStyleGrouped];
        zhltableView.delegate = self;
        zhltableView.dataSource = self;
        zhltableView.backgroundColor = rgbGray;
        zhltableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
        zhltableView.separatorInset=UIEdgeInsetsMake(0,0, 0, 0);
        zhltableView.showsVerticalScrollIndicator = NO;
        zhltableView.showsHorizontalScrollIndicator = NO;
        zhltableView.sectionFooterHeight = 0;
        [self.view addSubview:zhltableView];
        [zhltableView registerClass:[BuyerNewestTableViewCell class] forCellReuseIdentifier:BuyerNewestTableViewCellID];
        [zhltableView registerClass:[BuyerOwnTableViewCell class] forCellReuseIdentifier:BuyerOwnTableViewCellID];
        [zhltableView registerClass:[BuyerShareTableViewCell class] forCellReuseIdentifier:BuyerShareTableViewCellID];
        _refreshView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0, -50, zhltableView.frame.size.width, 50)];
        _refreshView.delegate = self;
        [zhltableView addSubview:_refreshView];
        [_refreshView refreshLastUpdatedDate];
        _loadMoreView = [[LoadMoreTableFooterView alloc] initWithFrame:CGRectMake(0, zhltableView.bounds.size.height, zhltableView.bounds.size.width, zhltableView.bounds.size.height)];        _loadMoreView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;        _loadMoreView.delegate = self;
        [_loadMoreView setBackgroundColor:[UIColor clearColor] textColor:nil arrowImage:nil];
        [zhltableView addSubview:_loadMoreView];
        zhltableView.backgroundView = self.tableviewBackView;
        _zhltableView = zhltableView;
    }
   
    
    return _zhltableView;
}
-(UIView *)tableviewBackView{
    
    
    if (!_tableviewBackView) {
        
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64)];
        UIImageView * icon = [[UIImageView alloc]initWithFrame:CGRectMake((view.frameWidth - 70)/2, (view.frameHeight - 60)/2, 70, 60)];
        icon.image = [UIImage imageNamed:@"xkf_noicon"];
        [view addSubview:icon];
        UILabel * title = [RHMethods labelWithFrame:CGRectMake(0, YH(icon) + 10, view.frameWidth, 10) font:Font(12) color:rgbTxtGray text:@"暂时没有信息哦~" textAlignment:NSTextAlignmentCenter];
        [view addSubview:title];
        
        _tableviewBackView = view;
        
        
        
    }
    
    
    return _tableviewBackView;
}
-(UIView *)HeaderView{
    
    if (!_HeaderView) {
        
        
        HeaderMenuVIew * tableivewHeaderView = [[HeaderMenuVIew alloc]initWithFrame:CGRectMake(0, 64,kScreenWidth,45)];
        tableivewHeaderView.backgroundColor = [UIColor whiteColor];
        tableivewHeaderView.titleArray = @[@"最新",@"自有",@"共享"];
        tableivewHeaderView.delegate = self;
        [tableivewHeaderView makeUI];
        _HeaderView = tableivewHeaderView;
        
    }
    return _HeaderView;
}

#pragma mark -  tableview代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    if (self.sharetype == 1) {
        
        return 1;
    }
    return 2;
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (self.sharetype == 0) {
     
        if (section == 0) {
            
            return self.newstModel.lists.count;
            
        }else{
            
            return self.newstModel.list.count;
    
        }
        
        
    }else if (self.sharetype == 1){
        
        return self.ownModel.list.count;
        
        
    }else if (self.sharetype == 2){
        
        if (section == 0) {
            
            return self.shareModel.lists.count;
            
        }else{
            
            return self.shareModel.list.count;
            
            
        }
        
    }
    
    return 0;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (self.sharetype) {
        case 0:
        {
            return 10+12+10+8+10;
        }
            break;
        case 1:
        {
            BuyerOwnListModel * model = self.ownModel.list[indexPath.row];
//            按布局从上到下算高度
            return
            10
            +[[NSString stringWithFormat:@"%@(%@)",model.name,model.companyname] HEIGHTwF:15 W:kScreenWidth - 20 - 10]
            +10
            +[[NSString stringWithFormat:@"%@ | %@ | %@)",model.mobile,model.wechat,model.email] HEIGHTwF:13 W:kScreenWidth - 20 - 10]
            +10
            +12
            +10;
        }
            break;
        case 2:
        {
            return 10+12+10+8+10;
            
        }
            break;
        default:
            return 0;
            break;
    }
    
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if (self.sharetype == 0) {
        if (section == 0) {
            if (self.newstModel.lists.count == 0) {
                return CGFLOAT_MIN;
            }
        }else{
            if (self.newstModel.list.count == 0) {
                return CGFLOAT_MIN;
            }
        }
    }else if (self.sharetype == 1){
        return 50;
    }else if (self.sharetype == 2){
        if (section == 0) {
            if (self.shareModel.lists.count == 0) {
                return CGFLOAT_MIN;
            }
        }else{
            if (self.shareModel.list.count == 0) {
                 return CGFLOAT_MIN;
            }
        }
    }
    
    return 30;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section    {
    
    
    
    return CGFLOAT_MIN;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //sharetype
    /**0最新*/
    /**1自有*/
    /**2共享*/
    switch (self.sharetype) {
        case 0:
        {
            UIView * headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
            headerview.backgroundColor = rgbGray;
            headerview.clipsToBounds = YES;
            UILabel * title = [RHMethods labelWithFrame:CGRectMake(10, 0, kScreenWidth - 20, headerview.frameHeight) font:Font(14) color:rgbTxtGray text:@"近三天"];
            if (section == 1) {
                
                title.text = @"三天前";
                
            }
            [headerview addSubview:title];
        
            return headerview;
        }
            break;
        case 1:
        {
            UIView * headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 50)];
            headerview.backgroundColor = rgbGray;
            UISearchBar * txtSearch= [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth-25-20, 50)];
            txtSearch.delegate=self;
            txtSearch.placeholder=@"按关键字搜索";
            [headerview addSubview:txtSearch];
            [txtSearch setBackgroundImage:[[Utility Share] imageFromColor:rgbGray rect:txtSearch.frame.size]];
            UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(XW(txtSearch) + 10, (headerview.frameHeight - 19)/2, 25, 19)];
            [button setImage:[UIImage imageNamed:@"xkf_menuicon"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(classData:) forControlEvents:UIControlEventTouchUpInside];
            [headerview addSubview:button];
            
            return headerview;
        }
            break;
        case 2:
        {
            UIView * headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
            headerview.backgroundColor = rgbGray;
            headerview.clipsToBounds = YES;
            UILabel * title = [RHMethods labelWithFrame:CGRectMake(10, 0, kScreenWidth - 20, headerview.frameHeight) font:Font(14) color:rgbTxtGray text:@"我的共享"];
            if (section == 1) {
                
                title.text = @"别人的共享";
                
            }
            [headerview addSubview:title];
            return headerview;
            
        }
            break;
        default:
            return [UIView new];
            break;
    }
    
}
#pragma mark  cell处理
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (self.sharetype) {
        case 0:
        {
            BuyerNewestTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:BuyerNewestTableViewCellID forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.backgroundColor = [UIColor whiteColor];
            if (indexPath.section == 0) {
                BuyerNewestListsModel * model = self.newstModel.lists[indexPath.row];
                cell.listsModel = model;
                
            }else{
                
                BuyerNewestListModel * model = self.newstModel.list[indexPath.row];
                cell.listModel = model;
                
            }
            
            return cell;
            
        }
            break;
        case 1:
        {
            BuyerOwnTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:BuyerOwnTableViewCellID forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.backgroundColor = [UIColor whiteColor];
            BuyerOwnListModel * model = self.ownModel.list[indexPath.row];
            cell.model = model;
            return cell;
            
        }
            break;
        case 2:
        {
            BuyerShareTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:BuyerShareTableViewCellID forIndexPath:indexPath];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.backgroundColor = [UIColor whiteColor];
            if (indexPath.section == 0) {
                BuyerShareListsModel * model = self.shareModel.lists[indexPath.row];
                cell.listsModel = model;
                
            }else{
                
                BuyerShareListModel * model = self.shareModel.list[indexPath.row];
                cell.listModel = model;
                
            }
            
            return cell;
            
        }
            break;
        default:
            return [UITableViewCell new];
            break;
    }
    
  
    
}
#pragma mark  选中cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    EMWeakSelf(weakSelf);
    NSLog(@"%@",indexPath);
    if (self.sharetype == 0) {
        
        [QAlertView showAlertViewWithTitle:@"是否接受买卖家？" message:@"" cancelButtonTitle:@"取消" OtherButtonsArray:@[@"确定"] clickAtIndex:^(NSInteger index) {
           
            if (index == 1) {
                
                
                if (indexPath.section == 0) {
                    BuyerNewestListsModel * model = weakSelf.newstModel.lists[indexPath.row];
                    
                    [weakSelf customercate:model.z_id];
                    
                }else{
                    
                    BuyerNewestListModel * model = weakSelf.newstModel.list[indexPath.row];
                    [weakSelf customercate:model.z_id];
                }
                
            }
           
            
            
        }];
        
        
        
    }else if (self.sharetype == 1){
        
        BuyerOwnListModel * model = self.ownModel.list[indexPath.row];
        NSMutableDictionary*mdic=[NSMutableDictionary new];
        [mdic setObject:model.z_id forKey:@"id"];
        
        [self pushController:[BuyerAndSellerDetailViewController class] withInfo:@"买家" withTitle:@"买家" withOther:mdic];
        
    }else if (self.sharetype == 2){
        
        if (indexPath.section == 0) {
            
            BuyerShareListsModel * model = self.shareModel.lists[indexPath.row];
            NSMutableDictionary*mdic=[NSMutableDictionary new];
            [mdic setObject:model.z_id forKey:@"id"];
            [self pushController:[BuyerAndSellerDetailViewController class] withInfo:@"买家" withTitle:@"买家" withOther:mdic];
            
        }else{
            
            
            BuyerShareListModel * model = self.shareModel.list[indexPath.row];
            NSMutableDictionary*mdic=[NSMutableDictionary new];
            [mdic setObject:model.z_id forKey:@"id"];
            [self pushController:[BuyerAndSellerDetailViewController class] withInfo:@"买家" withTitle:@"买家" withOther:mdic];
        }
        
        
    }
    
}
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self makeData:self.sharetype withMask:SVProgressHUDMaskTypeClear];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return refreshing; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}
#pragma mark - LoadMoreTableViewDelegate

- (void)loadMoreTableFooterDidTriggerLoadMore:(LoadMoreTableFooterView *)view
{
    [self makeMoreData:self.sharetype withMask:SVProgressHUDMaskTypeClear];
}
//接受
-(void)customercate:(NSString *)idd{
    

    krequestParam
    [dictparam setValue:idd forKey:@"id"];
    [NetEngine createHttpAction:@"customer/choosecustomer" withCache:NO withParams:dictparam withMask:SVProgressHUDMaskTypeClear onCompletion:^(id resData, BOOL isCache) {
        ;
        [SVProgressHUD showImage:nil status:[resData valueForJSONStrKey:@"info"]];
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            
            
            [self makeData:self.sharetype withMask:SVProgressHUDMaskTypeNil];
            
            
        }else{
            
            
            
            
            
            
        }
        
    } onError:^(NSError *error) {
        
    }];
    
    
    
}
//分类
-(void)classData:(UIButton *)button{
  
    krequestParam
    [NetEngine createHttpAction:@"customer/customercate" withCache:NO withParams:dictparam withMask:SVProgressHUDMaskTypeClear onCompletion:^(id resData, BOOL isCache) {
        
        if ([[resData valueForJSONStrKey:@"status"] isEqualToString:@"200"]) {
            
            NSDictionary * dic = resData[@"data"];
            NSArray * type = dic[@"type"];
            
            arrayTypeRight = [[NSMutableArray alloc]init];
            
            for (int i = 0; i < type.count; i ++) {
                NSDictionary * dit = type[i];
                NSMutableDictionary * data = [[NSMutableDictionary alloc]init];
                [data setValue:[dit valueForJSONStrKey:@"name"] forKey:@"title"];
                [data setValue:[dit valueForJSONStrKey:@"id"] forKey:@"id"];
                
                [arrayTypeRight addObject:data];
            }
            
            
            [self rightButtonClicked:button];
            
            
            
        }else{
            
            
            [SVProgressHUD showImage:nil status:[resData valueForJSONStrKey:@"info"]];
            
            
            
        }
        
    } onError:^(NSError *error) {
        
    }];
    
    
}
#pragma mark HeaderMenuVIewDelegate
-(void)HeaderMenuVIewDidIndex:(NSInteger)index{
    
    self.typeid = @"";
    self.sharetype = index;
    
    [self makeData:index withMask:SVProgressHUDMaskTypeClear];
    
}
-(void)rightButtonClicked:(UIButton *)button{
    if (!selctTypeView) {
        selctTypeView=[[SelectRightTypeView alloc] init];
        selctTypeView.dicType=@{@"list":arrayTypeRight};
        selctTypeView.contentConter=YES;
    }
    UIWindow * window = [[[UIApplication sharedApplication]delegate] window];
    CGRect rect = [button convertRect:button.bounds toView:window];
    selctTypeView.delegate=self;
    selctTypeView.point = CGPointMake(rect.origin.x + button.frameWidth, rect.origin.y + button.frameHeight + 15);
    
   
   
 
    [selctTypeView show];
}
#pragma mark SelectRightTypeViewDelegate
-(void)selectRightTypeView:(SelectRightTypeView *)sview object:(NSDictionary *)dic index:(NSIndexPath *)indexPath{
    
    self.typeid = [dic valueForJSONStrKey:@"id"];
    [self makeData:self.sharetype withMask:SVProgressHUDMaskTypeClear];
    
    
    
    
    
}
- (void)stopRefresh
{
    refreshing = NO;
    if (_refreshView) {
        [_refreshView egoRefreshScrollViewDataSourceDidFinishedLoading:_zhltableView];
    }
    
    //endRefresh];
}

- (void)stopLoadmore
{
    if (_loadMoreView) {
        [_loadMoreView egoRefreshScrollViewDataSourceDidFinishedLoading:_zhltableView];
    }
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    _refreshView.delegate?[_refreshView egoRefreshScrollViewDidScroll:scrollView]:nil;
    _loadMoreView.delegate?[_loadMoreView egoRefreshScrollViewDidScroll:scrollView]:nil;
   
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    _refreshView.delegate?[_refreshView egoRefreshScrollViewDidEndDragging:scrollView]:nil;
    _loadMoreView.delegate?[_loadMoreView egoRefreshScrollViewDidEndDragging:scrollView]:nil;
   
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    
    
    [self pushController:[BuyerSeacherViewController class] withOnlyInfo:nil];
    
    
    
    return NO;
}
-(void)backButtonClicked:(id)sender{
    
    if (self.block) {
        self.block();
    }
    [super backButtonClicked:sender];
}
@end
